Skip to content

Studio map: the C/C++ extractor, c-includes (#806) - #814

Merged
danielrispler merged 6 commits into
mainfrom
issue-806-c-includes
Nov 28, 2026
Merged

danielrispler merged 6 commits into
mainfrom
issue-806-c-includes

Conversation

@danielrispler

@danielrispler danielrispler commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

A new extractor, c-includes, reads every tracked C and C++ file (13 extensions, any case) as text and turns each #include into a pair. It reads no build file and runs no compiler (ADR 0002).

system-map/src/extract/c/
├── mod.rs             # reads/skips, two passes: settle every include and count evidence, then settle ties
├── lexer.rs           # comments, strings, raw strings, digit separators, splices → (path, quoted, line)
├── resolve.rs         # suffix index built once; steps 1-4
└── system_headers.rs  # the research's STD, PLATFORM, SYS_PREFIX, WIN lists
resolve(include)
  if quoted and the folder/path next to the file is tracked
    pair it, unless ignored or skipped → nothing; stop either way
  if angle and the path is a system header → nothing
  if the path has ".." → nothing
  candidates = tracked paths == path or ending "/path", less skipped
  none, or all ignored → nothing
  some ignored → Unsure "an ignored copy matches it"        (ADR 0004)
  one → pair
  several → the one candidate whose implied folder has ≥ 5 unique matches, else Unsure "several files match it"

The free scan's language table gains cxx c++ hh hxx h++ inl ipp tcc as C++, so First map's language line says "C and C++: links computed". map.md gets the c-includes section with its under- and over-counts. system-map.json needs no change: map-engine's "Extractors and links" already owns system-map/src/extract/.

Evidence

  • Before: a C or C++ repository has no reader, so every part is unread and every link passes as unproven. The scan names C and C++ as unread.
    After: system-map/tests/c.rs (behaviour tests, table-shaped), the contract cases on c-includes, and a new row in scan.rs's language test. npm run check passes at 680f0bd.

Trials (#810), at the research's commits, with the research's vendored trees ignored. Evidence is in local-evidence/2026-11-28-c-includes-trials/.

curl leveldb bitcoin redis
c-includes unique file pairs 2,542 354 4,961 591
research script, unique pairs 2,542 354 4,961 591
research script, directives 2,543 (2,541 + 2 wrong) 354 4,961 592
Unsure findings / files 0 0 128 / 112 3 / 3
imports --json wall 0.06-0.08 s 0.02 s 0.10-0.13 s 0.05-0.07 s
  • The pair sets and the Unsure (file, name) sets are identical to the research script's on all four repositories.
  • Directives and unique pairs differ only by repeated includes: curl's lib/vtls/rustls.c and redis's src/zmalloc.c each name one header twice.
  • curl's two known wrong lines are both present: <rustls.h> → lib/vtls/rustls.h and the VMS curlmsg_vms.h. Both are documented over-counts.
  • bitcoin's check takes 0.39-0.49 s, well under a second (the research's Python prototype took 1.4 s).
  • After the review fixes changed the lexer, a rerun on the four clones gave byte-identical imports --json and per-file check --json output.

Tests merged into tables (each passed before and after; every input survives as a row):

Removed test Now a row of
a_sibling_wins_over_a_root_relative_match_elsewhere candidates_are_files_whose_path_ends_with_the_include_after_a_slash
an_angle_bracket_include_skips_the_including_files_folder the same
a_tie_between_a_production_header_and_a_test_one_is_the_production_one the same
an_empty_absolute_or_backslashed_path_gives_nothing a_quoted_include_pairs_with_a_file_next_to_the_including_file
includes_inside_an_ignored_file_give_nothing an_ignored_or_skipped_file_gives_no_pair_and_an_adjacent_one_stops_the_search (renamed from an_adjacent_file_the_map_ignores_or_the_reader_skips_gives_no_pair_and_stops_the_search)

All of these were added in this PR. None is tagged @law.

Final review (standards, spec, correctness at /code-review high). No high or medium defects were found. Fixed in cfeb914:

  • The ADR 0004 path in map.md was wrong.
  • map.md dropped "(ignored or not)" from the evidence rule.
  • A test re-wrote the shared helper common::assert_only_candidate_links_relaxed.
  • The ignored-sibling case tested step 3, not step 1.
  • A C++14 digit separator (1'000) opened a fake char literal that hid a later /* or R"(.
  • A block comment spanning lines after code made the next # a directive.

Both lexer cases were reproduced against clang -E.

Left as they are:

  • A backslash with trailing spaces before the newline is not a continuation, because the spec says "a backslash at a line's end".
  • /* c */ #include pairs, as the preprocessor reads it.

Outside review

gemini-4-neon-medium. cost: 4.9 min, 277723 tokens; Gemini quota left: weekly 46% to 45%, 5h 97% to 92%

  1. Fixed (680f0bd). skip_quoted stepped a backslash over the line's end, so #error don't \\ + newline swallowed the next line's #include. It was red first. The correctness pass had not reported it.
  2. Fixed. No lexer row tested string skipping: neither string row had its # at a line's start. Added const char *s = "/*"; before an include. The correctness pass had not reported it.
  3. Fixed. The scan row tested only 3 of the 8 new C++ extensions. Each C++ extension is now its own row. The correctness pass had not reported it.

Route outcomes

Merge Danger

Door: two-way

A new extractor, used only by maps that name c-includes, plus 8 scan table rows. Reverting removes both. No stored type changes.

Blast Radius: small

plotkeeper's own check and imports print the same output, since it tracks no C or C++ file. A map that names c-includes on a C repository gains links, and some may now fail. That is the point of the change. The scan's C/C++ language line changes from no reader to "links computed".

Closes #806
Closes #807
Closes #808
Closes #809
Closes #810

🤖 Generated with Claude Code

https://claude.ai/code/session_01CVqACcz69cZfFntnejeG9g

danielrispler and others added 6 commits November 28, 2026 17:23
…e folder tie-break (#808)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACcz69cZfFntnejeG9g
The lexer reads a digit separator inside a number (`1'000`) as part of the
number, not as a character literal, and a block comment after code no longer
puts the next code at a line's start. map.md cites ADR 0004 by its file name,
restores "(ignored or not)" in the evidence rule and matches the sibling
sections' Under-/Over-counts form. c.rs folds its single-case tests into the
tables, adds the ignored-sibling row, and uses the shared Unsure helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACcz69cZfFntnejeG9g
A backslash right before a line's end no longer carries a string or
character literal onto the next line. The lexer table gains a row where a
string hides a comment opener, and the scan test checks each C++
extension alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACcz69cZfFntnejeG9g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment